package net.zjitc.servlet.category;

import net.zjitc.domain.Category;
import net.zjitc.domain.User;
import net.zjitc.service.CategoryService;
import net.zjitc.service.UserService;
import net.zjitc.service.impl.CategoryServiceImpl;
import net.zjitc.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * 2 * @Author: 洪瑶
 * 3 * @Date: 2018/10/29 18:49
 * 4
 */
@WebServlet(name = "AllServlet",urlPatterns = "/allServlet")
public class AllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        CategoryService service = new CategoryServiceImpl();
        List<Category> list = null;
        try {
            list = service.findAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        session.setAttribute("list",list);
        request.getRequestDispatcher("common/category/category.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
